package com.java.basic;

public class ThreadLocalTest2 {

    public static void main(String[] args){

        ThreadLocal threadLocal = new InheritableThreadLocal();
        threadLocal.set("父数据");
        Thread t1 = new Thread(()->{
                System.out.println("当前线程["+Thread.currentThread().getName()+"]获得的数据:"+threadLocal.get());
        },"线程1");

        Thread t2 = new Thread(()->{
            try {
                t1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("当前线程["+Thread.currentThread().getName()+"]获得的数据:"+threadLocal.get());
        },"线程2");
        t1.start();
        t2.start();
        threadLocal.remove();

    }
}
